home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / nShell-Pro.sit / nShell-Pro / doc / nShell™ User's Guide.rsrc / TEXT_135.txt < prev    next >
Text File  |  1994-12-27  |  2KB  |  76 lines

  1.  
  2. Scripting
  3.  
  4. nShell(tm) scripts are simple text files.  They may be created and edited in any text editor, including the TeachText and SimpleText programs provided with your Macintosh.
  5.  
  6. To create a script, type the series of commands you wish to execute into a file and save it in your current working directory.  (The shell searches your "command search path" for scripts just as it does commands.)
  7.  
  8. You can put comments in scripts using the "#" character.
  9.  
  10. Simple Scripts
  11.  
  12. As an example, consider the "echo" command.  Echo repeats a string to the shell window, as in:
  13.  
  14. % echo "this is me"
  15. this is me
  16.  
  17. If I were to take these lines:
  18.  
  19. # This is a comment
  20. echo "I am a script"
  21. echo "and I am fine."
  22.  
  23. and save them in a text file called "yak", I could type yak and get the following:
  24.  
  25. % yak
  26. I am a script
  27. and I am fine.
  28.  
  29. Scripts can call other scripts just as they can call commands.  If I were to take the lines:
  30.  
  31. # This time we do it twice
  32. yak
  33. echo "tell me again?"
  34. yak
  35.  
  36. and save them in a file called "two", I could type two and get the following:
  37.  
  38. % two
  39. I am a script
  40. and I am fine.
  41. tell me again?
  42. I am a script
  43. and I am fine.
  44.  
  45. Script Parameters
  46.  
  47. You can pass parameters to scripts just as you can with commands.  When a script is executed its parameters are stored in shell variables.  The variables used are $#, $0, $1, $2...
  48.  
  49. $# contains the number of passed parameters
  50. $0 contains the name of the script
  51. $1 contains the first parameter
  52. $2 contains the second parameter
  53. ...
  54.  
  55. We can demonstrate this with the simple script called "kitty":
  56.  
  57. echo $#
  58. echo $0
  59. echo $1
  60. echo $2
  61.  
  62. Running kitty, we get:
  63.  
  64. % kitty is fine
  65. 3
  66. kitty
  67. is
  68. fine
  69.  
  70. Variables in Scripts
  71.  
  72. In addition to shell parameters, the "set" "unset" and "env" commands may be used to create and modify variables within a script.
  73.  
  74. It is important to note that while a script may modify any variable, all changes are temporary and are discarded when the script terminates.
  75.  
  76.